import syc from "./syc.js";
runOnStartup(async runtime => {
    //runtime.addEventListener("tick", () => tick())
    //runtime.getLayout("MainLevel").addEventListener("afterlayoutstart", () => init())
    window.addEventListener("levelInit", () => {
        MovePlayerEvent.init()
    })
    window.addEventListener("levelTick", () => {
        MovePlayerEvent.tick()
    })
});
class MovePlayerEvent {
    static init() {
        MovePlayerEvent.initPlayerCompent()
    }
    static tick() {
        MovePlayerEvent.move()
        MovePlayerEvent.jump()
    }
    static initPlayerCompent() {
        /**@type {ISpriteInstance} */
        this.playerMask = runtime.objects.PlayerCollision?.getFirstInstance()
        /**@type {I8DirectionBehaviorInstance} */
        this.playerMaskMoveBehavior = this.playerMask?.behaviors['8Direction']
        /**@type {ISpriteInstance} */
        this.playerboard = runtime.objects.PlayerBillboard?.getFirstInstance()
    }
    static move() {
        if (runtime.keyboard.isKeyDown("KeyA")) {
            this.playerMaskMoveBehavior.simulateControl("left")
        }
        if (runtime.keyboard.isKeyDown("KeyD")) {
            this.playerMaskMoveBehavior.simulateControl("right")
        }
        if (runtime.keyboard.isKeyDown("KeyW")) {
            this.playerMaskMoveBehavior.simulateControl("up")
        }
        if (runtime.keyboard.isKeyDown("KeyS")) {
            this.playerMaskMoveBehavior.simulateControl("down")
        }
    }
    static jump() {
        if (runtime.keyboard.isKeyDown("KeyJ")) {
            runtime.callFunction("playerJumpFucntion",)
            //影子
            /**@type {ISpriteInstance} */
            const playerShadow = runtime.objects.PlayerShadow.getFirstInstance()
            playerShadow.isVisible = true
            setTimeout(function () {
                playerShadow.isVisible = false
            }, 200)
        }
    }
}
export default MovePlayerEvent;